﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransCend.Model;

namespace TransCend.DAL
{
    public class Column
    {
        public static readonly int DefaultLength = -1;

        private DataType _type;
        private int _length;
        private string _name;
        private bool _nullable;
        private string _alias;
        private AutoGenerateAttribute autoGenerateAttribute;
        private object _default;

        public Column(ColumnAttribute column)
        {
            _type = column.DataType;
            _length = column.Length;
            _name = column.Name;
            _nullable = column.Nullable;
            _alias = column.Alias;
            _insertable = column.Insert;
            _updatable = column.Update;
            _default = column.Default;
        }

        /// <summary>
        /// Get or set the column name
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Alias
        {
            get { return _alias == null ? _name : _alias; }
            set { _alias = value; }
        }

        /// <summary>
        ///	Get or set the column type
        /// </summary>
        public DataType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        ///	Get or set the column length or precision
        /// </summary>
        public int Length
        {
            get { return _length; }
            set { _length = value; }
        }

        /// <summary>
        /// Get or set if this column could be NULL
        /// </summary>
        public bool Nullable
        {
            get { return this._nullable; }
            set { this._nullable = value; }
        }

        private bool _insertable = true;
        public bool Insertable
        {
            get { return _insertable; }
            set { _insertable = value; }
        }

        private bool _updatable = true;
        public bool Updatable
        {
            get { return _updatable; }
            set { _updatable = value; }
        }

        public AutoGenerateAttribute AutoGenerateAttribute
        {
            get { return autoGenerateAttribute; }
            set { autoGenerateAttribute = value; }
        }

        public object Default
        {
            get { return _default; }
            set { _default = value; }
        }
    }
}
